<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>产品分类编辑</title>
	<meta name="keywords" content="">
	<meta name="description" content="">
	<link href="${ctxPath}/static/admin/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
	<script src="${ctxPath}/static/admin/js/plugins/sweetalert/sweetalert.min.js"></script>
	
	<link rel="stylesheet" type="text/css" href="${ctxPath}/static/admin/js/plugins/wangEditor/dist/css/wangEditor.min.css">
	
	<link rel="shortcut icon" href="${ctxPath}/views/admin/favicon.ico">
	<link href="${ctxPath}/static/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
	<link href="${ctxPath}/static/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
	<link href="${ctxPath}/static/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
	<link href="${ctxPath}/static/admin/css/animate.css" rel="stylesheet">
	<link href="${ctxPath}/static/admin/css/style.css?v=4.1.0" rel="stylesheet">
	<link href="${ctxPath}/static/admin/css/plugins/webuploader/webuploader.css" rel="stylesheet">
	<style>
		#category_info{resize:none;}
	</style>
</head>

<body class="gray-bg">

	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>产品分类信息</h5>
						<div class="ibox-tools">
							<a class="close-link" href="${ctxPath}/product/index">
								<button type="button" class="btn btn-default btn-sm"
									style="position: absolute; margin-bottom: 0px; bottom: 0px; right: 0px;">返回上一页</button>
							</a>
						</div>
					</div>
					<div class="ibox-content">
						<form action="${ctxPath}/product/save" method="post" name="form" id="form" class="form-horizontal" enctype="multipart/form-data">
							<div class="hr-line-dashed"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label">产品名称</label>
								<div class="col-sm-10">
									<div class="row">
										<div class="col-md-5">
											<input type="text" maxlength="8" placeholder="产品名称" class="form-control"
												id="product_name" name="product_name"  value="${data.product_name!}">
												<input type="hidden" id="id" name="id"  value="${data.id!}">
										</div>
									</div>
								</div>
							</div>
							<div class="hr-line-dashed"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label">产品内容</label>
								<div class="col-sm-10">
									<div class="row">
										<div class="col-md-10">
											<textarea id="product_info" name="product_info" style="height:400px;">
												${data.product_info!}
											</textarea>
										</div>
									</div>
								</div>
							</div>
							<div class="hr-line-dashed"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label">产品大图</label>
								<div id="uploader-demo">
                                	<label>
                                		<p class="webuploader-pick">选择图片</p><p style="color:red;">(请选用 1080 * 900 尺寸的图片)</p>
                                		<input id="file" type="file" name="pic" onchange="goodsImg(this)" style="display:none;">
                                	</label>
								</div>
							</div>
							<div class="form-group" style="dispaly:none;">
                            	<label class="col-sm-2 control-label" style="margin-right:16px;"></label>
                            	<div id="imgDiv">
                            		<!--# if(data.big_img! != ""){ -->
                            			<img src="${ctxPath}/down/downProductImg?imgUrl=${data.big_img!}" style="width:540px; height:400px;"/>
                            		<!--# } -->
                            		<input type="hidden" id="imgFix" name="imgFix" value="${data.big_img!}"/>
                            	</div>
                            </div>
                            <div class="hr-line-dashed"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label">产品小图</label>
								<div id="uploader-demo">
                                	<label>
                                		<p class="webuploader-pick">选择图片</p><p style="color:red;">(请选用 240 * 200 尺寸的图片)</p>
                                		<input id="file1" type="file" name="pic1" onchange="goodsImg(this)" style="display:none;">
                                	</label>
								</div>
							</div>
							<div class="form-group" style="dispaly:none;">
                            	<label class="col-sm-2 control-label" style="margin-right:16px;"></label>
                            	<div id="imgDiv1">
                            		<!--# if(data.small_img! != ""){ -->
                            			<img src="${ctxPath}/down/downProductImg?imgUrl=${data.small_img!}" style="width:240px; height:200px;"/>
                            		<!--# } -->
                            		<input type="hidden" id="imgFix1" name="imgFix1" value="${data.small_img!}"/>
                            	</div>
                            </div>
							<div class="hr-line-dashed"></div>
                            <div class="form-group">
								<label class="col-sm-2 control-label">产品分类</label>
		                        <div class="col-sm-10">
									<div class="row">
										<div class="col-sm-2 m-b-xs">
			                                <select id="type_id" name="type_id" class="input-sm form-control input-s-sm inline" style="height:40px;">
			                                    <option value="0">请选择</option>
			                                    <!--# for(var res in category){ -->
				                                    <option ${data.type_id! == res.id?'selected':''} value="${res.id!}">${res.type_name!}</option>
				                                <!--# } -->
			                                </select>
			                            </div>
									</div>
								</div>
							</div>
							<div class="hr-line-dashed"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label">产品排序</label>
								<div class="col-sm-10">
									<div class="row">
										<div class="col-md-2">
											<input type="text" placeholder="分类排序" class="form-control"
												id="sort" name="sort" value="${data.sort!}" onblur="num_check($(this).val())">
										</div>
									</div>
								</div>
							</div>
							<div class="hr-line-dashed"></div>
							<div class="form-group">
								<div class="col-sm-4 col-sm-offset-2">
									<button id="btn_save" type="button" class="btn btn-primary">保存内容</button>
									<a href="${ctxPath}/product/index" class="btn btn-white">取消</a>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>



	<!-- 全局js -->
	<script src="${ctxPath}/static/admin/js/jquery.min.js?v=2.1.4"></script>
	<script src="${ctxPath}/static/admin/js/bootstrap.min.js?v=3.3.6"></script>
	<script src="${ctxPath}/static/admin/js/plugins/webuploader/webuploader.js"></script>
    <script src="${ctxPath}/static/js/ajaxfileupload.js"></script>

	<!-- 自定义js -->
	<script src="${ctxPath}/static/admin/js/content.js?v=1.0.0"></script>
	
	<script type="text/javascript" src="${ctxPath}/static/admin/js/plugins/wangEditor/dist/js/lib/jquery-1.10.2.min.js"></script>
	<script type="text/javascript" src="${ctxPath}/static/admin/js/plugins/wangEditor/dist/js/wangEditor.min.js"></script>

	<!-- iCheck -->
	<script src="${ctxPath}/static/admin/js/plugins/iCheck/icheck.min.js"></script>
	<script>
        $(document).ready(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        });
        
        
        var editor = new wangEditor('product_info');
        editor.config.menus = [
         ];
        
        editor.create();
    </script>
	<script type="text/javascript">
		function num_check(a){
	        var m =a ;
			var partten =/^\+?(0|[1-9][0-9]*)$/;
			if (m != '') {
				if (!partten.test(m)) {
					swal({
						  title: "提示",
						  text: "请输入整数",
						  timer: 1000,
						  showConfirmButton: false
						});
					return false;
				}
			}
		}
		
		//图片预览及上传
        function goodsImg(file){
			if(file.id == 'file'){
				var imgDiv = document.getElementById('imgDiv');
	        	console.log(file.value);
	        	if (file.files && file.files[0]){
	        		var reader = new FileReader();
	        		reader.onload = function(evt){
	        			imgDiv.innerHTML = '<img src="' + evt.target.result + '" style="width:1080px; height:900px;"/><input type="hidden" id="imgFix" name="imgFix" value=""/>';
	        		}
	        		reader.readAsDataURL(file.files[0]);
	        	}else{
	        		imgDiv.innerHTML = '<div id="imgFix" class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
	        	}
			}else{
				var imgDiv = document.getElementById('imgDiv1');
	        	console.log(file.value);
	        	if (file.files && file.files[0]){
	        		var reader = new FileReader();
	        		reader.onload = function(evt){
	        			imgDiv.innerHTML = '<img src="' + evt.target.result + '" style="width:240px; height:200px;"/><input type="hidden" id="imgFix1" name="imgFix1" value=""/>';
	        		}
	        		reader.readAsDataURL(file.files[0]);
	        	}else{
	        		imgDiv.innerHTML = '<div id="imgFix1" class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
	        	}
			}
        }
		
		//提交
		$("#btn_save").on("click", function(){
			if($("#product_name").val() == "" || $("#product_name").val() == null || 
			   editor.$txt.html() == "" || editor.$txt.html() == null ||
			   $("#type_id").val() == "" || $("#type_id").val() == null ||
			   $("#sort").val() == "" || $("#sort").val() == null
			   ){
				swal({
           		  title: "提示",
           		  text: "部分选项内容为空，请检查后提交",
           		  timer: 1500,
           		  showConfirmButton: false
           		});
				return false;
			}
			if($("#file").val() == ""){
				if($("#imgFix").val() == ""){
					swal({
	           		  title: "提示",
	           		  text: "图片不可为空,请上传图片后提交",
	           		  timer: 1500,
	           		  showConfirmButton: false
	           		});
					return false;
				}
			}
			if($("#fil1").val() == ""){
				if($("#imgFix1").val() == ""){
					swal({
	           		  title: "提示",
	           		  text: "图片不可为空,请上传图片后提交",
	           		  timer: 1500,
	           		  showConfirmButton: false
	           		});
					return false;
				}
			}
			editor.$txt.html();
			$("#product_info").val(encodeURIComponent(encodeURIComponent(editor.$txt.html())));
			$("#product_info").val(decodeURIComponent(decodeURIComponent(editor.$txt.html())));
			$("#form").submit();
		})
		
	</script>



</body>

</html>
